﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;


namespace Portal
{
    /// <summary>
    /// EF数据库连接类
    /// </summary>
    public class ProtalContext : DbContext
    {
        /// <summary>
        /// 静态构造函数中配置数据库 更新方式
        /// </summary>
        static ProtalContext()
        {
            Database.SetInitializer(new DropCreateDatabaseIfModelChanges<ProtalContext>());
        }

        /// <summary>
        /// 构造函数中来读取配置文件中的连接字符串
        /// </summary>
        public ProtalContext():base("name=PortalContext")
        {

        }

        public DbSet<Entities.Province> Provinces { get; set; }
        public DbSet<Entities.Category> Categorys { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //通过连接方式添加 映射类
            //base.OnModelCreating(modelBuilder);
            modelBuilder.Configurations.Add(new Maping.CategoryMap());
            modelBuilder.Configurations.Add(new Maping.ProvinceMap());

        }

    }
}
